#include <stdio.h>
#include <stdlib.h>

int extract_min(int * array) {
	int n = array[0];
	
	int temp = array[1];
	array[1] = array[n];
	array[n] = temp;
	
	array[0]--;
	n--;

	int cur = 1;
	while (1) {
		if (cur * 2 > n)
			break;

		int smaller = 2*cur;	//assume the left child is smaller
		if (2*cur + 1 <= n && array[2*cur] > array[2*cur + 1]) //the right child exist and it is smaller
			smaller++;
		if (array[cur] <= array[smaller])
			break;

		int temp = array[cur];
		array[cur] = array[smaller];
		array[smaller] = temp;
		cur = smaller;
	}

	return array[n+1];
}

void build_heap(int * array) {
	int n = array[0];

	for (int i = n/2; i >= 1; --i) {
		int cur = i;

		while(1) {
			if (cur*2 > n)	//cur has no left child, so it has no right child
				break;

			int smaller = 2*cur;	//assume the left child is smaller
			if (2*cur + 1 <= n && array[2*cur] > array[2*cur + 1]) //the right child exist and it is smaller
				smaller++;
			if (array[cur] <= array[smaller])
				break;
			
			int temp = array[cur];
			array[cur] = array[smaller];
			array[smaller] = temp;
			cur = smaller;
		}
	}
}

/**
 * partition array[start..end] using pivot s.t.:
 * return the index position of the pivot.
 *
 * array[start..pos] <= array[pos] = pivot < array[pos + 1..end]
 */
int partition(int * array, int start, int end) {
	if (start >= end)
		return -1;
	int pivot = array[start];

	int i = start, j = start;
	for (; j <= end; ++j) {
		if (array[j] <= pivot) {
			++i;
			++j;
		}
	}	
}

int main() {
	while(1) {
		int n, k;
		scanf("%d%d", &n, &k);

		//heap index starts from 1
		//use array[0] to store the size of the heap
		int * array = (int *) malloc(sizeof(int) * (n + 1));

		array[0] = n;
		for (int i = 1; i <= n; ++i)
			scanf("%d", &array[i]);

		if (k >= n) {
			for (int i = 1; i <= n; ++i)
				printf("%d ", array[i]);
			return 0;
		}

#define USE_HEAP
#ifdef USE_HEAP
		/**
		 * use the binary heap to extract mins in a for-loop. 
		 * build heap: O(n);
		 * extract mins for k times: k*log(n);
		 * total: O(n)
		 */
		build_heap(array);
		for (int i = 0; i < k; ++i)
			printf("%d ", extract_min(array));
#endif

#ifdef USE_DIVIDE_CONQUER
		/**
		 * use the divide and conquer algorithm
		 * partition like quick sort does
		 */ 

		
#endif
		free(array);
	}
	return 0;
}
